package com.houger.ddd.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.scripting.support.ResourceScriptSource;

/**
 * @author Houger.
 * @date 2024年04月23日 14:42.
 */
@Configuration
public class LuaConfiguration {
    @Bean("sendRedPacketLuaScript")
    public DefaultRedisScript<String> sendRedPacketLuaScript() {
        DefaultRedisScript<String> redisScript = new DefaultRedisScript<>();
        redisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("script/sendRedPacket.lua")));
        redisScript.setResultType(String.class);
        return redisScript;
    }

    @Bean("grabRedPacketLuaScript")
    public DefaultRedisScript<String> grabRedPacketLuaScript() {
        DefaultRedisScript<String> redisScript = new DefaultRedisScript<>();
        redisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("script/grabRedPacket.lua")));
        redisScript.setResultType(String.class);
        return redisScript;
    }
}
